package com.example.hasee.test.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;

import com.example.hasee.test.R;
import com.example.hasee.test.lvxingActivity;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.jude.rollviewpager.hintview.ColorPointHintView;

/**
 * A simple {@link Fragment} subclass.
 */
public class oneFragment extends Fragment implements View.OnClickListener {
    private RollPagerView mViewPager;
    private RadioButton b1,b2,b3,b4,b5,b6;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_one, container, false);
        b1 = view.findViewById(R.id.b1);
        b2 = view.findViewById(R.id.b2);
        b3 = view.findViewById(R.id.b3);
        b4 = view.findViewById(R.id.b4);
        b5 = view.findViewById(R.id.b5);
        b6 = view.findViewById(R.id.b6);
        b1.setOnClickListener(this);
        b2.setOnClickListener(this);
        b3.setOnClickListener(this);
        b4.setOnClickListener(this);
        b5.setOnClickListener(this);
        b6.setOnClickListener(this);

        mViewPager = view.findViewById(R.id.mViewPager);
        //设置播放时间间隔
        mViewPager.setPlayDelay(1000);
        //设置透明度
        mViewPager.setAnimationDurtion(500);
        //设置适配器
        mViewPager.setAdapter(new TestNormalAdapter());
        mViewPager.setHintView(new ColorPointHintView(getActivity(), Color.YELLOW, Color.WHITE));

        return view;


    }

    @Override
    public void onClick(View view) {
        Intent intent = new Intent(getActivity(), lvxingActivity.class);
        switch (view.getId()){
            case R.id.b1:
                startActivity(intent);
                break;

            case R.id.b2:
                startActivity(intent);
                break;
            case R.id.b3:
                startActivity(intent);
                break;
            case R.id.b4:
                startActivity(intent);
                break;
            case R.id.b5:
                startActivity(intent);
                break;
            case R.id.b6:
                startActivity(intent);
                break;
        }
    }

    private class TestNormalAdapter extends StaticPagerAdapter {
        private int[] imgs = {
                R.drawable.icon1,
                R.drawable.icon2,
                R.drawable.icon3,
                R.drawable.icon4,
        };
        @Override
        public View getView(ViewGroup container, int position) {
            ImageView view = new ImageView(container.getContext());
            view.setImageResource(imgs[position]);
            view.setScaleType(ImageView.ScaleType.CENTER_CROP);
            view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            return view;
        }
        @Override
        public int getCount() {
            return imgs.length;
        }
    }
}